<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->


    <link href="__ADMIN_TMPL__/public/assets/themes/{:cmf_get_admin_style()}/bootstrap.min.css" rel="stylesheet">
    <link href="__ADMIN_TMPL__/public/assets/simpleboot3/css/simplebootadmin.css" rel="stylesheet">
    <link href="__ADMIN_TMPL__/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        form .input-order {
            margin-bottom: 0px;
            padding: 0 2px;
            width: 42px;
            font-size: 12px;
        }

        form .input-order:focus {
            outline: none;
        }

        .table-actions {
            margin-top: 5px;
            margin-bottom: 5px;
            padding: 0px;
        }

        .table-list {
            margin-bottom: 0px;
        }

        .form-required {
            color: red;
        }
    </style>
    <script type="text/javascript">
        //全局变量
        var GV = {
            ROOT: "__ROOT__/",
            WEB_ROOT: "__WEB_ROOT__/",
            JS_ROOT: "static/js/",
            APP: '{$Request.module}'/*当前应用名*/
        };
    </script>
    <script src="__ADMIN_TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
    <script src="__STATIC__/js/wind.js"></script>
    <script src="__ADMIN_TMPL__/public/assets/js/bootstrap.min.js"></script>
    <script>
        Wind.css('artDialog');
        Wind.css('layer');
        $(function () {
            $("[data-toggle='tooltip']").tooltip({
                container:'body',
                html:true,
            });
            $("li.dropdown").hover(function () {
                $(this).addClass("open");
            }, function () {
                $(this).removeClass("open");
            });
        });
    </script>
    <if condition="APP_DEBUG">
        <style>
            #think_page_trace_open {
                z-index: 9999;
            }
        </style>
    </if>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:cmf_plugin_url('QbtDbBackup://AdminIndex/index')}">数据备份</a></li>
        <li class="active"><a href="{:cmf_plugin_url('QbtDbBackup://AdminIndex/list1')}">数据还原</a></li>
    </ul>
    <form action="" method="post" class="margin-top-20">
        <div class="table-actions">
            <a class="btn btn-danger btn-sm" onclick="restore()">还原</a><span class="ts" style="display: none;color: #f00;margin-left: 10px;">至少选择一项</span>
        </div>
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th width="16">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th colspan="2">表名</th>
                <th>备份时间</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="tables[]"
                               value="{$vo['name']}">
                    </td>
                    <td>{$vo['name']}</td>
                    <td class="zt" style="width: 200px;"></td>
                    <td>{$vo['time']}</td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/noty/noty-2.4.1.js"></script>
<script>
    function restore() {
        var str=[];
        var len = 0;
        var dir = '{$dir}';
        $(".js-check").each(function(){
            if ($(this).is(':checked')){
                str.push($(this).val());
                $(this).parent().parent().find('.zt').html('<span style="color:#aaa;">正在恢复...</span>');
                var a = $(this).parent().parent().find('.zt');
                $.ajax({
                    type: "GET",
                    url: "{:cmf_plugin_url('QbtDbBackup://AdminIndex/restore')}",
                    data: {str:$(this).val(),dir:dir},
                    dataType: "json",
                    success: function(data){
                        if (data===1){
                            len++;
                            console.log(data);
                            a.html('<span style="color:#0a0;">恢复完成</span>');
                            if (str.length===len){
                                noty({text: "还原成功", type: 'success',layout: "topCenter", timeout: 2000});
                            }
                        }else{
                            a.html('<span style="color:#f00;">恢复失败</span>')
                        }
                    }
                });
            }
        });
        if (str.length==0){
            $(".ts").show();
        }
    }
</script>
</body>
</html>